<div class="list">
	<div class="list_title clearfix">
		<div {if $ACTION_NAME eq 'index'}class="cur"{/if}><a href="{url x="index" r="uc_account#index"}">{$LANG.UC_ACCOUNT}</a></div>
	</div>
	<div class="uc_r_bl_box clearfix">
	<style>
		.field{ width:520px}
	</style>
	<div class="blank"></div>
	<form method="post" action="{url x="shop" r="uc_account#save"}" name="modify">
	<div class="inc wb">
		<div class="inc_main">
				<table width="800px" class="user_info_table">
					<tr>
						<td colspan=2 class="tr">
							<button type="button" class="true_btn" id="edit-account">编辑资料</button>
						</td>
					</tr>
					<tr>
						<td class="pt10" valign="top" style="width:180px; text-align:center">
								<img id="avatar" src="{function name="get_user_avatar" uid=$user_info.id type="middle"}" />
								<div class="blank"></div>
								<div class="hide account-edit-box">
									<label class="fileupload" onclick="upd_file(this,'avatar_file',{$user_info.id});">
									<input type="file" class="filebox" name="avatar_file" id="avatar_file"/>
									
									</label>
									<label class="fileuploading hide" ></label>						
								</div>	
						</td>
						
						<td class="pt10" >
							
							<div class="field username">
								<label for="settings-username"><span class="red">*</span>{$LANG.USER_TITLE_USER_NAME}</label>
								<span class="f_l">{$user_info.user_name}</span>
							</div>
							<div class="blank10"></div>
							<div class="field email">
								<label for="settings-email-address"><span class="red">*</span>Email</label>
								<span class="f_l">{function name="hideEmail" v=$user_info.email}</span>
								{if $user_info.email neq '' && $user_info.emailpassed eq 1}
									<span class="passed yes">已绑定</span>
								{elseif $user_info.email neq '' && $user_info.emailpassed eq 0}
									<span class="passed yes">已设置</span>
								{else}
									<span class="passed"><a href="{url x="index" r="uc_account#security"}">去设置</a></span>
								{/if}
								
							</div>
							<div class="blank10"></div>
														
							<div class="field real_name">
								<label for="settings-real_name"><span class="red">*</span>{$LANG.REAL_NAME}</label>
								<span class="f_l">{function name="utf_substr" v="$user_info.real_name"}</span>
								{if $user_info.idcardpassed eq 1}
									<span class="passed yes">已认证</span>
								{else}
									<span class="passed"><a href="{url x="index" r="uc_account#security"}">去认证</a></span>
								{/if}
							</div>
							<div class="blank10"></div>
							<div class="field idno">
								<label for="settings-idno"><span class="red">*</span>{$LANG.IDNO}</label>
								<span class="f_l">{function name="hideIdCard" v=$user_info.idno}</span>
								{if $user_info.idcardpassed eq 1}
									<span class="passed yes">已认证</span>
								{else}
									<span class="passed"><a href="{url x="index" r="uc_account#security"}">去认证</a></span>
								{/if}
							</div>
							<div class="blank10"></div>
							<div class="field mobile">
								<label for="settings-mobile"><span class="red">*</span>{$LANG.USER_TITLE_MOBILE}</label>
								<span class="f_l">{function name="hideMobile" v=$user_info.mobile}</span>
								{if $user_info.mobilepassed eq 1}
									<span class="passed yes">已绑定</span>
								{else}
									<span class="passed"><a href="{url x="index" r="uc_account#security"}">去绑定</a></span>
								{/if}
							</div>
							<div class="blank10"></div>
							<div class="field">
								<label><span class="red">*</span>{$LANG.USER_SEX}</label>
								<span class="f_l">
								{if $user_info.sex eq 0}{$LANG.USER_SEX_0}{/if}
								{if $user_info.sex eq 1}{$LANG.USER_SEX_1}{/if}
								</span>
							</div>
							<div class="blank10"></div>
							<div class="field clearfix">
								<label for="settings-birthday"><span class="red">*</span>{$LANG.USER_BIRTHDAY}</label>
								<div class="f_l">
									{$user_info.byear}
									-
									{$user_info.bmonth}
									-
									{$user_info.bday}
									
								</div>
							</div>
							<!--显示框开始-->
							<div class="account-view-box">
								<div class="blank10"></div>
								<div class="field graduation">
									<label for="settings-graduation"><span class="red">*</span>{$LANG.GRADUATION}</label>
									<span class="f_l">
									{if $user_info.graduation eq $LANG.GRADUATION_1}{$LANG.GRADUATION_1}{/if}
									{if $user_info.graduation eq $LANG.GRADUATION_2}{$LANG.GRADUATION_2}{/if}
									{if $user_info.graduation eq $LANG.GRADUATION_3}{$LANG.GRADUATION_3}{/if}
									{if $user_info.graduation eq $LANG.GRADUATION_4}{$LANG.GRADUATION_4}{/if}
									</span>
								</div>
								<div class="blank10"></div>
								<div class="field university">
									<label for="university">{$LANG.UNIVERSITY}</label>
									<span class="f_l">{$user_info.university}</span>
								</div>
								<div class="blank10"></div>
								<div class="field marriage">
									<label><span class="red">*</span>{$LANG.MARRIAGE}</label>
									<span class="f_l">{$user_info.marriage}</span>
								</div>
								
								{foreach from=$field_list item=field_item}
								<div class="blank10"></div>
								<div class="field {$field_item.field_name}">
									<label for="{$field_item.field_name}">{if $field_item.is_must eq 1}<span class="red">*</span>{/if}{$field_item.field_show_name}</label>
									<span class="f_l">{$field_item.value}</span>
								</div>
								{/foreach}
								
								<div class="blank10"></div>
								<div class="field">								
									<label for="settings-region"><span class="red">*</span>{$LANG.USER_REGION}</label>
									<span class="f_l">
									{$region_lv2_name}
									{$region_lv3_name}
									</span>
								</div>
								<div class="blank10"></div>
								<div class="field address">
									<label for="settings-address"><span class="red">*</span>{$LANG.ADDRESS}</label>
									<span class="f_l">{$user_info.address}</span>
								</div>
								<div class="blank10"></div>
								<div class="field phone">
									<label for="settings-phone">{$LANG.PHONE}</label>
									<span class="f_l">{$user_info.phone}</span>
								</div>
							</div>
							<!--显示框结束-->
							<!--编辑框开始-->
							<div class="hide account-edit-box">
								<div class="blank10"></div>
								<div class="field graduation">
									<label for="settings-graduation"><span class="red">*</span>{$LANG.GRADUATION}</label>
									<select name="graduation" id="settings-graduation" class="f_l">
										<option value="" {if $user_info.graduation eq ''}selected="selected"{/if}>={$LANG.SELECT_PLEASE}=</option>
										<option value="{$LANG.GRADUATION_1}" {if $user_info.graduation eq $LANG.GRADUATION_1}selected="selected"{/if}>{$LANG.GRADUATION_1}</option>
										<option value="{$LANG.GRADUATION_2}" {if $user_info.graduation eq $LANG.GRADUATION_2}selected="selected"{/if}>{$LANG.GRADUATION_2}</option>
										<option value="{$LANG.GRADUATION_3}" {if $user_info.graduation eq $LANG.GRADUATION_3}selected="selected"{/if}>{$LANG.GRADUATION_3}</option>
										<option value="{$LANG.GRADUATION_4}" {if $user_info.graduation eq $LANG.GRADUATION_4}selected="selected"{/if}>{$LANG.GRADUATION_4}</option>
									</select>
								</div>
								<div class="blank10"></div>
								<div class="field university">
									<label for="university">{$LANG.UNIVERSITY}</label>
									<input type="text" value="{$user_info.university}" class="f-input f_l" id="settings-university" name="university" size="30">
								</div>
								<div class="blank10"></div>
								<div class="field marriage">
									<label><span class="red">*</span>{$LANG.MARRIAGE}</label>
									<span class="f_l">
									<input type="radio" class="f-radio" value="已婚" name="marriage" {if $user_info.marriage eq '已婚'}checked="checked"{/if}> 已婚
									&nbsp;&nbsp;&nbsp;&nbsp;
									<input type="radio" class="f-radio" value="未婚" name="marriage" {if $user_info.marriage eq '未婚'}checked="checked"{/if}> 未婚
									&nbsp;&nbsp;&nbsp;&nbsp;
									<input type="radio" class="f-radio" value="离异" name="marriage" {if $user_info.marriage eq '离异'}checked="checked"{/if}> 离异
									&nbsp;&nbsp;&nbsp;&nbsp;
									<input type="radio" class="f-radio" value="丧偶" name="marriage" {if $user_info.marriage eq '丧偶'}checked="checked"{/if}> 丧偶
									</span>
								</div>
								
								{foreach from=$field_list item=field_item}
								<div class="blank10"></div>
								<div class="field {$field_item.field_name}">
										<label for="{$field_item.field_name}">{if $field_item.is_must eq 1}<span class="red">*</span>{/if}{$field_item.field_show_name}</label>
										{if $field_item.input_type eq 0}
										<input type="text" value="{$field_item.value}" class="f-input f_l" id="settings-{$field_item.field_name}" name="{$field_item.field_name}" size="30">
										{else}
										<select name ="{$field_item.field_name}" id="settings-{$field_item.field_name}" class="f_l">
											{foreach from=$field_item.value_scope item=value_item}
											<option value="{$value_item}" {if $value_item eq $field_item.value}selected="selected"{/if}>{if $value_item eq ''}={$LANG.SELECT_PLEASE}={else}{$value_item}{/if}</option>
											{/foreach}
										</select>
										{/if}
								</div>
								{/foreach}
								
								<script type="text/javascript" src="{$APP_ROOT}/system/region.js"></script>		
								
								<div class="blank10"></div>
								<div class="field">
																				
									<label for="settings-region"><span class="red">*</span>{$LANG.USER_REGION}</label>
									<span class="f_l">
										<select name="province_id">
											<option value="0">={$LANG.SELECT_PLEASE}=</option>
											{foreach from=$region_lv2 item=lv2}
											<option {if $lv2.selected eq 1}selected="selected"{/if} value="{$lv2.id}">{$lv2.name}</option>
											{/foreach}
										</select>
																
										<select name="city_id">
											<option value="0">={$LANG.SELECT_PLEASE}=</option>		
											{foreach from=$region_lv3 item=lv3}
											<option {if $lv3.selected eq 1}selected="selected"{/if} value="{$lv3.id}">{$lv3.name}</option>
											{/foreach}
										</select>
									</span>
								</div>
								<div class="blank10"></div>
								<div class="field address">
									<label for="settings-address"><span class="red">*</span>{$LANG.ADDRESS}</label>
									<input value="{$user_info.address}" class="f-input f_l" name="address" id="settings-address">
								</div>
								<div class="blank10"></div>
								<div class="field phone">
									<?php $phone_s = explode("-",$this->_var['user_info']['phone']);?>
									<label for="settings-phone">{$LANG.PHONE}</label>
									<input class="f-input f-input60" type="text" value="<?php echo $phone_s[0];?>" class="f-input f_l" id="frphone" onkeyup="setPhone();" onblur="setPhone();">
									<span class="f_l">&nbsp;-&nbsp;</span>
									<input class="f-input" type="text" value="<?php echo $phone_s[1];?>" class="f-input f_l" id="numphone" onkeyup="setPhone();" onblur="setPhone();">
									<input type="hidden" value="{$user_info.phone}" name="phone" id="phone">
								</div>
							</div>
							<!--编辑框结束-->
						</td>
						
					</tr>
					
				</table>
				<div class="blank20"></div>
				<div style="text-align:center">
					<div class="hide account-edit-box">
						<input type="submit" class="sub_btn" id="settings-submit" name="commit" value="保存更改">
					</div>
				</div>
				<div class="blank"></div>
		</div>
		<div class="inc_foot"></div>
	</div>
	</form>
	</div>
</div>
<script type="text/javascript" src="{$TMPL}/js/ajaxupload.js"></script>
<script type="text/javascript">
function setPhone(){
	var frphone = $.trim($("#frphone").val());
	var numphone = $.trim($("#numphone").val());
	if(frphone!=""&&numphone!=""){
		$("#phone").val(frphone+"-"+numphone);
	}
	else{
		$("#phone").val("");
	}
}
$(document).ready(function(){

	$("#settings-submit").click(function(){
		{if $user_info.email eq ''}
		if($.trim($("#settings-email-address").val()).length == 0)
		{
			$("#settings-email-address").focus();
			$.showErr("{function name="sprintf" format=$LANG.EMPTY_ERROR_TIP value=$LANG.USER_TITLE_EMAIL}");
			
			return false;
		}
		
		if(!$.checkEmail($("#settings-email-address").val()))
		{
			$("#settings-email-address").focus();			
			$.showErr("{function name="sprintf" format=$LANG.FORMAT_ERROR_TIP value=$LANG.USER_TITLE_EMAIL}");
			return false;
		}
		{/if}
		
		
		var is_marriage = false;
		$("input[name='marriage']").each(function(){
			if($(this).attr("checked")=="checked" || $(this).attr("checked")==true){
				is_marriage = true;
			}
		});
		
		if(!is_marriage){
			$.showErr("{function name="sprintf" format=$LANG.EMPTY_ERROR_TIP value=$LANG.MARRIAGE}");
			return false;
		}
		
		
		if($.trim($("#settings-graduation").val()).length == 0){
			$("#settings-graduation").focus();
			$.showErr("{function name="sprintf" format=$LANG.EMPTY_ERROR_TIP value=$LANG.GRADUATION}");
			
			return false;
		}
		
		{foreach from=$field_list item=field_item}
			{if $field_item.is_must eq 1}
			if($("#settings-{$field_item.field_name}").val()=='')
			{
				$.showErr("{function name="sprintf" format=$LANG.EMPTY_ERROR_TIP value=$field_item.field_show_name}");	
				$("#settings-{$field_item.field_name}").focus();
				return false;
			}
			{/if}
		{/foreach}
		
		if($("select[name='province_id']").val()== 0||$("select[name='city_id']").val() == 0)
		{
			$("select[name='province_id']").focus();
			$.showErr("{function name="sprintf" format=$LANG.EMPTY_ERROR_TIP value=$LANG.USER_REGION}");
			
			return false;
		}
		
		if($.trim($("#settings-address").val()).length == 0){
			$("#settings-address").focus();
			$.showErr("{function name="sprintf" format=$LANG.EMPTY_ERROR_TIP value=$LANG.ADDRESS}");
			
			return false;
		}

	});
});

function upd_file(obj,file_id,uid)
{	
	$("input[name='"+file_id+"']").bind("change",function(){			
		$(obj).hide();
		$(obj).parent().find(".fileuploading").removeClass("hide");
		$(obj).parent().find(".fileuploading").removeClass("show");
		$(obj).parent().find(".fileuploading").addClass("show");
		  $.ajaxFileUpload
		   (
			   {
				    url:APP_ROOT+'/index.php?ctl=avatar&act=upload&uid='+uid,
				    secureuri:false,
				    fileElementId:file_id,
				    dataType: 'json',
				    success: function (data, status)
				    {
				   		$(obj).show();
				   		$(obj).parent().find(".fileuploading").removeClass("hide");
						$(obj).parent().find(".fileuploading").removeClass("show");
						$(obj).parent().find(".fileuploading").addClass("hide");
				   		if(data.status==1)
				   		{
				   			document.getElementById("avatar").src = data.middle_url+"?r="+Math.random();
				   		}
				   		else
				   		{
				   			$.showErr(data.msg);
				   		}
				   		
				    },
				    error: function (data, status, e)
				    {
						$.showErr(data.responseText);;
				    	$(obj).show();
				    	$(obj).parent().find(".fileuploading").removeClass("hide");
						$(obj).parent().find(".fileuploading").removeClass("show");
						$(obj).parent().find(".fileuploading").addClass("hide");
				    }
			   }
		   );
		  $("input[name='"+file_id+"']").unbind("change");
	});	
}

//切换地区
$(document).ready(function(){	
		$("select[name='province_id']").bind("change",function(){
			load_city($("select[name='province_id']"),$("select[name='city_id']"));
		});
		
	});
	
	function load_city(pname,cname)
	{
		var id = pname.val();
		var evalStr="regionConf.r"+id+".c";

		if(id==0)
		{
			var html = "<option value='0'>="+LANG['SELECT_PLEASE']+"=</option>";
		}
		else
		{
			var regionConfs=eval(evalStr);
			evalStr+=".";
			var html = "<option value='0'>="+LANG['SELECT_PLEASE']+"=</option>";
			for(var key in regionConfs)
			{
				html+="<option value='"+eval(evalStr+key+".i")+"'>"+eval(evalStr+key+".n")+"</option>";
			}
		}
		cname.html(html);
	}
	
</script>